package com.cpkso.yzx.repository;

import java.util.List;

import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.cpkso.yzx.domain.Role;

import runze.util.base.HibernateDaoImp;
import runze.util.base.IDao;

/**
 * 根据role的userid获取request？
 * 
 * @author wrzhxy@qq.com
 * @date 2017年11月11日
 */
@SuppressWarnings("unchecked")
@Repository
public class RoleRepository extends HibernateDaoImp<Role> implements IDao<Role> {
	private static final String FindRoleByUserId = "select req.url from Role r inner join r.users u inner join r.requests req where u.id=?";

	/**
	 * 根据userid获取role
	 * 
	 * @param id
	 * @return
	 */
	public List<String> findByUserId(Integer id) {
		try {
			Session session = getSessionFactory().getCurrentSession();
			List<String> list = (List<String>) session.createQuery(FindRoleByUserId).setLong(0, id).list();
			return list.size() < 1 ? null : list;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

}
